//=============================================================================

#include "../inc/aJoint.h"

//=============================================================================

#define DEFAULT "defaultJoint"

//=============================================================================

aJoint::aJoint()
{
  memset(bindMatrix, 0, sizeof(float)*matrixSize);
  memset(currentMatrix, 0, sizeof(float)*matrixSize);
  parent = 0;
  weights = 0;
  name = DEFAULT;
}

//=============================================================================

aItem<aAnimationsTrack>* aJoint::ajGetAnimationByName(const aString& name) const
{
  if (name.asGetLength() <= 0)
    return 0;
  
  aItem<aAnimationsTrack>* tmpAnim = track.alGetFirstItem();

  while(tmpAnim)
  {
    if (tmpAnim->data.caption == name)
      return tmpAnim;

    tmpAnim = tmpAnim->next;
  }

  return 0;
}

//=============================================================================

void aJoint::ajCopyDataToCurrentMatrix()
{
    currentMatrix[0] = ijk[0].x;
    currentMatrix[1] = ijk[0].y;
    currentMatrix[2] = ijk[0].z;
    currentMatrix[4] = ijk[1].x;
    currentMatrix[5] = ijk[1].y;
    currentMatrix[6] = ijk[1].z;
    currentMatrix[8] = ijk[2].x;
    currentMatrix[9] = ijk[2].y;
    currentMatrix[10] = ijk[2].z;
    currentMatrix[12] = position.x;
    currentMatrix[13] = position.y;
    currentMatrix[14] = position.z;
}

//=============================================================================

aJoint::~aJoint()
{
  if (weights)
    delete [] weights;
}

//=============================================================================
